<?php
if ( !defined('IN_ADMINCP') || !defined('IN_SEC') ){
	exit('Access Denied.');
}
$admins = parse_array(DB::limit('admincp_member'));
$deliverys = parse_array(limitcache('delivery', 'delivery'), 'name');
$action = in_array($_G['gp_act'], array('del')) ? $_G['gp_act'] : 'edit';
$id = intval($_G['gp_id']);
if ( $id && !$delivery = fetch('delivery', $id) ){
	$admincp->cpmsg('不存在该快递');
}
if ( is_post() ){
	if ( $action == 'edit' ){
		$name = $_G['gp_name'] ? $_G['gp_name'] : $admincp->cpmsg('请输入快递名称');
		$desc = $_G['gp_desc'] ? $_G['gp_desc'] : '';
		$price = is_numeric($_G['gp_price']) ? moneyit($_G['gp_price']) : 0;
		$update = array(
			'name' => $name,
			'description' => $desc,
			'price' => $price,
		);
		if ( $delivery ){
			updatecache('delivery', $delivery['id'], $update, 'delivery');
		}else{
			if ( $deliverys[$name] ){
				$admincp->cpmsg('快递已存在，如不存在请清空缓存后操作');
			}
			$update['adminid'] = $admincp->admin['id'];
			$update['create_time'] = SYS_TIME;
			DB::Insert('delivery', $update);
			delcache('delivery');
		}
		Session::Set('notice', '操作成功');
		refresh(HTTP_REFERER);
	}elseif( $action == 'del' ){
		if ( $delivery ){
			DB::Delete('delivery', array('id' => $delivery['id']));
			delcache('delivery');
			refresh(HTTP_REFERER);
		}
	}
}

?>